package Timer_TimerTask;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lishuo
 * Date: 2023-04-05
 * Time: 16:18
 */
public class Test_Official_Timer {
    public static void main(String[] args) {
        Timer timer = new Timer();
        // 这里的TimerTask就相当于Runnable
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("world1");
            }
        },1000);

        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("world2");
            }
        },2000);

        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("world3");
            }
        },3000);

        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("world4");
            }
        },4000);

        System.out.println("hello!");
    }
}
